﻿using DC2010.Objects.Base;
using DC2010.Objects;
using DC2010.Objects.Data;

namespace DC2010.Effects
{
    public class I_Teleport_Effect : EffectLogic
    {
        public I_Teleport_Effect(EffectData ed)
            : base(ed)
        {
            ShortName = "TELEPORT";
            LongName = "Teleports party or creature to destination.";
            EffectType = EffectType.Instant;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="aInvoker">Who activated the teleporter</param>
        /// <param name="aTarget">Who will be teleported</param>
        public override void Instant(BaseObject aInvoker, BaseObject aTarget)
        {
            string Floor = Data.Params.Find(A => A.Key == "FLOOR").Value;
            int X = Data.Params.Find(A => A.Key == "X").Value.ToInt();
            int Y = Data.Params.Find(A => A.Key == "Y").Value.ToInt();
            
            //this is impossible branch....because every creature must be in party. Even if party have only one member.
            if (aTarget is CreatureData)
            {
                CreatureData aCreature = (CreatureData)aTarget;

                //teleport
                aCreature.Location.FloorId = Floor;
                aCreature.Location.X = X;
                aCreature.Location.Y = Y;
            }

            if (aTarget is PartyData)
            {
                PartyData aParty = (PartyData)aTarget;
                aParty.Location.FloorId = Floor;
                aParty.Location.X = X;
                aParty.Location.Y = Y;
            }
        }
    }
}
